package com.Maykk.Demo02;

/**
 * @ClassName: Student
 * @Description: TODO
 * @Author: MaykkStar@163.com
 */
public class Student implements Comparable<Student> {
    private String name;
    private int age;

    public Student(String name, int age) {
        this.name = name;
        this.age = age;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    @Override
    public String toString() {
        return "Student{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }

    @Override
    public int compareTo(Student o) {
        // return 0;// 0 表示相等，后面的值存入不进去
        // return 1; // 大于0，表示o对象比当前的对象大，放到后面
        // return -1; // 小于0，表示o对象比当前的对象小，放到前面
        int res = this.getAge() - o.getAge();
        return 0 == res ? this.getName().compareTo(o.getName()) : res;
        // 如果 res == 0 ,就对比姓名, 如果 res != 0 ,返回 res
        }
}
